import xlwt

# 创建book,并设定编码
workbook = xlwt.Workbook(encoding='ascii')
#创建新的sheet表
worksheet = workbook.add_sheet('new sheet')

# 写入内容
worksheet.write(0, 0, 'hello world')
style = xlwt.XFStyle() # 创建样式对象
al = xlwt.Alignment() # 创建对齐方式对象
al.horz = 0x02 # 设置水平居中
al.vert = 0x01 # 设置垂直居中
style.alignment = al # 将对齐方式对象赋值给样式对象

worksheet.write(0, 1, 'world is beautiful', style)
# 保存
workbook.save('test8.xls')

